package com.ten.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ten.common.core.entity.AclRole;
import com.ten.common.core.entity.AclUser;
import com.ten.common.core.vo.Result;
import com.ten.system.service.AclRoleService;
import com.ten.system.vo.FenRoleVo;
import com.ten.system.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：Q大侠
 * @date ：Created in 2022/12/5 18:26
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/system/role")
@Api(tags = "角色的API接口类")
public class AclRoleController {
    @Autowired
    private AclRoleService aclRoleService;

    @GetMapping("finRoleByUserId/{userid}")
    public Result finRoleByUserId(@PathVariable Long userid){
        return aclRoleService.finRoleByUserId(userid);
    }

    @PostMapping("fenUserRole")
    public Result fenUserRole(@RequestBody FenRoleVo fenRoleVo){
        return aclRoleService.fenUserRole(fenRoleVo);
    }

    /** 
     * @create by:  Q大侠
     * @description:  根据条件分页查询角色信息
     * @create time: 2022/12/7 11:00
      * @param roleVo,current,pageSize
     * @return  
     */
    @ApiOperation(value = "根据条件分页查询角色信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示的条数")
    })
    @PostMapping("/findRoleByPage/{current}/{pageSize}")
    public Result findRoleByPage(@RequestBody RoleVo roleVo,
                                 @PathVariable Integer current,
                                 @PathVariable Integer pageSize
    ){
        return aclRoleService.findByConditionPage(roleVo,current,pageSize);
    }

    @PostMapping("updateRoleStatusByid/{id}/{deleted}")
    @ApiOperation(value = "根据角色id修改禁用/启用(is_deleted)")
    @ApiImplicitParams({@ApiImplicitParam(value = "角色id",name = "id"),@ApiImplicitParam(value = "禁用/启用",name = "deleted")})
    public Result updateRoleStatusByid(@PathVariable String id,@PathVariable int deleted){
        return aclRoleService.updateRoleStatusByid(id,deleted);
    }

    @PostMapping("addOrUpdateRole")
    @ApiOperation(value = "添加角色")
    public Result addOrUpdateRole(@RequestBody AclRole aclRole){
        return aclRoleService.addOrUpdateRole(aclRole);
    }

    @DeleteMapping("deleteRoleById/{id}")
    @ApiOperation(value = "根据角色id删除角色")
    @ApiImplicitParams({@ApiImplicitParam(value = "角色id",name = "id")})
    public Result deleteRoleById(@PathVariable String id){
        return aclRoleService.deleteRoleById(id);
    }

    @PostMapping("updateRoleById")
    @ApiOperation(value = "根据角色对象修改角色信息")
    public Result updateRoleById(@RequestBody AclRole aclRole){
        return aclRoleService.updateRoleById(aclRole);
    }

}
